﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace sy4_8
{
    public partial class Form1 : Form
    {
        // 窗体实例化（写在所有事件处理程序外部）
        private Form2 form2 = new Form2();
        private Form3 form3 = new Form3();
        private Form4 form4 = new Form4();
        private Form5 form5 = new Form5();
        private Form6 form6 = new Form6();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "多重窗体应用程序演示";
            toolStripStatusLabel1.Text = "就绪";
        }

        #region 菜单栏事件
        // 程序1菜单项
        private void 程序1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowForm2();
        }

        // 程序2菜单项
        private void 程序2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowForm3();
        }

        // 程序3菜单项
        private void 程序3ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowForm4();
        }

        // 程序4菜单项
        private void 程序4ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowForm5();
        }

        // 退出菜单项
        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        // 关于菜单项
        private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowForm6();
        }
        #endregion

        #region 工具栏事件
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            ShowForm2();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            ShowForm3();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            ShowForm4();
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            ShowForm5();
        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            ShowForm6();
        }
        #endregion

        #region 快捷菜单事件
        private void 程序1ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ShowForm2();
        }

        private void 程序2ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ShowForm3();
        }

        private void 程序3ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ShowForm4();
        }

        private void 程序4ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ShowForm5();
        }
        #endregion

        #region 显示窗体的方法
        private void ShowForm2()
        {
            form2.Show();
            form2.BringToFront();
            toolStripStatusLabel1.Text = "正在运行：程序1";
        }

        private void ShowForm3()
        {
            form3.Show();
            form3.BringToFront();
            toolStripStatusLabel1.Text = "正在运行：程序2";
        }

        private void ShowForm4()
        {
            form4.Show();
            form4.BringToFront();
            toolStripStatusLabel1.Text = "正在运行：程序3";
        }

        private void ShowForm5()
        {
            form5.Show();
            form5.BringToFront();
            toolStripStatusLabel1.Text = "正在运行：程序4";
        }

        private void ShowForm6()
        {
            form6.ShowDialog(); // 关于对话框使用ShowDialog
            toolStripStatusLabel1.Text = "显示关于信息";
        }
        #endregion

        // 主窗体关闭事件
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            // 关闭所有子窗体
            form2.Close();
            form3.Close();
            form4.Close();
            form5.Close();
            form6.Close();
        }
    }
}